<template>
  <div class="shop-container">
    <div class="shop-inner">
      <div class="mui-card" v-for="item in car_goods" :key="item.id">
        <div class="mui-card-content">
          <div class="mui-card-content-inner top">
            <mt-switch
              v-model="$store.getters.getGoodsSelected[item.id]"
              @change="
                changeSelected(
                  item.id,
                  $store.getters.getGoodsSelected[item.id]
                )
              "
            ></mt-switch>
            <img src="../static/imgs/cbd.jpg" alt="" />
            <div class="info">
              <h1>
                Apple MacBook Air 13.3 八核M1芯片(7核图形处理器) 8G 256G SSD
                深空灰 笔记本电脑 MGN63CH/A
              </h1>
              <div class="price-info">
                <span class="price">￥1999</span>
                <shop-num-box
                  :initcount="item.count"
                  :id="item.id"
                ></shop-num-box>
                <a href="" @click.prevent="remove(item.id)">删除</a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner jiesuan">
          <div class="left">
            <p>总结（不含运费）</p>
            <p>
              已勾选商品
              <span class="red">{{
                $store.getters.getGoodsCountAndAmount.count
              }}</span>
              件，总计:
              <span class="red"
                >￥{{ $store.getters.getGoodsCountAndAmount.amount }}</span
              >
            </p>
          </div>
          <mt-button type="danger">去结算</mt-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import ShopNumBox from "./subcomponents/ShopNumBox.vue";
import mui from "../lib/mui/js/mui.min.js";
export default {
  name: "ShopContainer",
  data() {
    return {
      car_goods: this.$store.state.car,
    };
  },
  components: {
    ShopNumBox,
  },
  mounted() {
    mui(".mui-switch")["switch"]();
  },
  methods: {
    remove(id) {
      this.$store.commit("removeFromCar", id);
    },
    changeSelected(id, selected) {
      this.$store.commit("updateGoodsSelected", { id, selected });
    },
  },
};
</script>

<style lang="less" scoped>
.shop-inner {
  overflow: hidden;
  background-color: #ccc;

  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    img {
      width: 60px;
      height: 60px;
    }
    .info {
      width: 64%;
      h1 {
        font-size: 13px;
      }
      .price-info {
        .price {
          color: red;
          font-weight: bold;
        }
        .mui-numbox {
          height: 25px;
        }
      }
    }
  }
}
.jiesuan {
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left {
    font-size: 12px;
    .red {
      color: red;
      font-size: 16px;
      font-weight: bold;
    }
  }
}
</style>